<template>
  <div class="app-container">
    <!-- 顶部banner -->
    <header class="app-header">
      <div class="logo">Vue AI 示例</div>
      <div class="user-info" v-if="isLoggedIn">
        <span class="username">{{ username }}</span>
        <el-button type="text" @click="logout" class="logout-btn">退出</el-button>
      </div>
    </header>

    <div class="main-container">
      <!-- 左侧菜单 -->
      <div class="sidebar">
        <el-menu
          class="sidebar-menu"
          :default-active="activeMenu"
          router
        >
          <el-menu-item index="/">
            <el-icon><i class="el-icon-s-home"></i></el-icon>
            <span>首页</span>
          </el-menu-item>
          
          <el-menu-item index="/tav">
            <el-icon><i class="el-icon-connection"></i></el-icon>
            <span>测试Axios</span>
          </el-menu-item>
          
          <el-menu-item index="/zxyf">
            <el-icon><i class="el-icon-data-analysis"></i></el-icon>
            <span>测试智学云帆Axios</span>
          </el-menu-item>
          
          <el-menu-item index="/stream">
            <el-icon><i class="el-icon-refresh"></i></el-icon>
            <span>测试流式响应</span>
          </el-menu-item>
          
          <el-menu-item index="/chat">
            <el-icon><i class="el-icon-chat-dot-round"></i></el-icon>
            <span>在线聊天</span>
          </el-menu-item>
          
          <el-menu-item index="/wish-wall">
            <el-icon><i class="el-icon-star-on"></i></el-icon>
            <span>高考许愿墙</span>
          </el-menu-item>
          
          <el-menu-item index="/complex">
            <el-icon><i class="el-icon-film"></i></el-icon>
            <span>剧本管理</span>
          </el-menu-item>
          
          <el-sub-menu index="editors">
            <template #title>
              <el-icon><i class="el-icon-edit-outline"></i></el-icon>
              <span>富文本编辑器</span>
            </template>
            <el-menu-item index="/richtext">Quill编辑器</el-menu-item>
            <el-menu-item index="/tinymce">简易编辑器</el-menu-item>
            <el-menu-item index="/ckeditor">CKEditor编辑器</el-menu-item>
            <el-menu-item index="/tiptap">TipTap编辑器</el-menu-item>
          </el-sub-menu>
        </el-menu>
      </div>
      
      <!-- 右侧内容区 -->
      <div class="content-area">
        <router-view></router-view>
      </div>
    </div>

    <footer class="app-footer">
      <p>&copy; 2023 Vue AI 示例项目</p>
    </footer>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import { useRoute, useRouter } from 'vue-router'

const route = useRoute()
const router = useRouter()

// 当前激活的菜单项
const activeMenu = computed(() => {
  return route.path
})

// 用户信息
const username = ref('')
const isLoggedIn = ref(false)

// 检查登录状态
const checkLoginStatus = () => {
  const loginStatus = localStorage.getItem('isLogin')
  const storedUsername = localStorage.getItem('username') || 'demo'
  
  isLoggedIn.value = loginStatus === '1'
  username.value = storedUsername
}

// 退出登录
const logout = () => {
  localStorage.removeItem('isLogin')
  localStorage.removeItem('username')
  isLoggedIn.value = false
  router.push('/login')
}

// 页面加载时检查登录状态
if (typeof window !== 'undefined') {
  checkLoginStatus()
}
</script>

<style scoped>
.app-container {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.app-header {
  background-color: #409eff;
  padding: 15px 20px;
  box-shadow: 0 2px 4px rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: white;
  height: 64px;
}

.logo {
  font-size: 24px;
  font-weight: bold;
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.username {
  font-weight: bold;
}

.logout-btn {
  color: white;
}

.main-container {
  display: flex;
  flex: 1;
}

.sidebar {
  width: 240px;
  border-right: 1px solid #ebeef5;
  background-color: #fff;
  height: calc(100vh - 64px - 46px); /* 减去header和footer的高度 */
  overflow-y: auto;
}

.sidebar-menu {
  border-right: none;
}

.content-area {
  flex: 1;
  padding: 20px;
  overflow-y: auto;
  height: calc(100vh - 64px - 46px); /* 减去header和footer的高度 */
}

.app-footer {
  background-color: #f8f9fa;
  padding: 15px;
  text-align: center;
  color: #606266;
  border-top: 1px solid #e6e6e6;
  height: 46px;
}

@media (max-width: 768px) {
  .main-container {
    flex-direction: column;
  }
  
  .sidebar {
    width: 100%;
    height: auto;
    border-right: none;
    border-bottom: 1px solid #ebeef5;
  }
  
  .content-area {
    height: auto;
  }
}
</style> 